package com.lagou.module4.work01;

public class Staff {

    private String name;
    private int age;

    public Staff(String name, int age) throws StaffAgeException {
        setName(name);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name ==null || "".equals(name)){
            throw new NullPointerException("姓名不能为空");
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws StaffAgeException {
        if(age<18 || age>150){
            throw new StaffAgeException("年龄不可小于18或者大于150");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
